<template>
  <div class="app-container">
    <div class="block">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input v-model="listQuery.criteria.name" size="mini" placeholder="名称"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="success" size="mini" icon="el-icon-search" @click.native="search">搜索</el-button>
          <el-button type="primary" size="mini" icon="el-icon-refresh" @click.native="reset">重置</el-button>
        </el-col>
      </el-row>
      <br>
      <el-row>
        <el-col :span="24">
          <el-button type="success" size="mini" icon="el-icon-plus" @click.native="add">添加</el-button>
          <el-button type="primary" size="mini" icon="el-icon-edit" @click.native="edit">修改</el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click.native="remove">删除</el-button>
        </el-col>
      </el-row>

    </div>

    <el-row>
      <el-col :span="20">

        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row
          :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }"
          @current-change="handleCurrentChange">
          <el-table-column label="客户名称">
            <template slot-scope="scope">
              {{ scope.row.name }}
            </template>
          </el-table-column>

          <el-table-column label="公司名称">
            <template slot-scope="scope">
              {{ scope.row.companyName }}
            </template>
          </el-table-column>

          <el-table-column label="联系人">
            <template slot-scope="scope">
              {{ scope.row.contact }}
            </template>
          </el-table-column>

          <el-table-column label="电话">
            <template slot-scope="scope">
              {{ scope.row.phoneNumber }}
            </template>
          </el-table-column>

          <el-table-column label="邮箱">
            <template slot-scope="scope">
              {{ scope.row.email }}
            </template>
          </el-table-column>

          <el-table-column label="地址">
            <template slot-scope="scope">
              {{ scope.row.address }}
            </template>
          </el-table-column>

          <el-table-column label="备注">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>

          <el-table-column label="顺序">
            <template slot-scope="scope">
              {{ scope.row.num }}
            </template>
          </el-table-column>

          <el-table-column label="状态">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status === '0'" @change="changeStatus(scope.row.id)"></el-switch>
            </template>
          </el-table-column>

          <el-table-column label="操作">
            <template slot-scope="scope">
                            <el-button type="text" size="mini" icon="el-icon-edit"
                                @click.native="editItem(scope.row)">修改</el-button>
                            <el-button  type="text"
                                size="mini" icon="el-icon-delete" @click.native="removeItem(scope.row)">删除</el-button>
                        </template>

          </el-table-column>

        </el-table>

        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 500]"
          :page-size="listQuery.limit" :total="total" :current-page.sync="listQuery.page" @size-change="changeSize"
          @current-change="fetchPage" @prev-click="fetchPrev" @next-click="fetchNext">
        </el-pagination>
      </el-col>
    </el-row>

    <el-dialog :title="formTitle" :visible.sync="formVisible" width="70%">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="name">
              <el-input v-model="form.name" minlength=1 clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="companyName">
              <el-input v-model="form.companyName" minlength=1 clearable></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="联系人" prop="contact">
              <el-input v-model="form.contact" minlength=1 clearable></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="电话" prop="phoneNumber">
              <el-input v-model="form.phoneNumber" minlength=1 clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址" prop="address">
              <el-input v-model="form.address" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" clearable></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="排序" prop="num">
              <el-input type="number" v-model="form.num" clearable></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-form-item>
          <el-button type="primary" @click.native="save">提交</el-button>
          <el-button @click.native="formVisible = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script src="./customer.js"></script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>